/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditDataSiswa.java
 *
 * Created on Nov 25, 2012, 3:12:21 PM
 */
package Form;

import Boundary.TU;
import Boundary.User;
import Boundary.siswa;
import Control.TUkontrol;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Boriz
 */
public class EditDataSiswa extends javax.swing.JDialog {

    /**
     * Creates new form EditDataSiswa
     */
    public EditDataSiswa(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel5 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        Updatebutton = new javax.swing.JButton();
        Batalbutton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        Nistextfield = new javax.swing.JTextField();
        NamaTextField = new javax.swing.JTextField();
        AlamatTextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        Kelastextfield = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        JenisKelaminCombo = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        Keluar = new javax.swing.JButton();

        jLabel5.setText("jLabel5");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel4.setText("Kelas");

        jLabel3.setText("Nama Siswa");

        Updatebutton.setText("Update");
        Updatebutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UpdatebuttonActionPerformed(evt);
            }
        });

        Batalbutton.setText("Batal");

        jLabel2.setText("Nis");

        Nistextfield.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NistextfieldActionPerformed(evt);
            }
        });

        jLabel6.setText("Alamat");

        jLabel7.setText("Jenis Kelamin");

        JenisKelaminCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "L", "P" }));

        jLabel1.setFont(new java.awt.Font("Century Gothic", 0, 36)); // NOI18N
        jLabel1.setText("Edit Data Siswa");

        Keluar.setText("Keluar");
        Keluar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                KeluarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel7))
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(Batalbutton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Updatebutton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Keluar)
                        .addGap(0, 22, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(AlamatTextField)
                            .addComponent(Kelastextfield)
                            .addComponent(NamaTextField)
                            .addComponent(Nistextfield, javax.swing.GroupLayout.Alignment.LEADING))
                        .addGap(80, 80, 80))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(JenisKelaminCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(43, 43, 43))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(48, 48, 48)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Nistextfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(NamaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(Kelastextfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(AlamatTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JenisKelaminCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(19, 19, 19)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Batalbutton)
                    .addComponent(Updatebutton)
                    .addComponent(Keluar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void UpdatebuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UpdatebuttonActionPerformed
        // TODO add your handling code here:
        siswa s = new siswa();
        TU tu = new TU();
        String nama = NamaTextField.getText();
        String no = Nistextfield.getText();
        String Kelas = Kelastextfield.getText();
        String alamat = AlamatTextField.getText();
        String jeniskelamin = JenisKelaminCombo.getSelectedItem().toString();

        s.setNIS(no);
        tu.setNis(s);
        s.setNama(nama);
        tu.setNama(s);
        s.setKelas(Kelas);
        tu.setKelas(s);
        s.setAlamat(alamat);
        tu.setAlamat(s);
        s.setJeniskelamin(jeniskelamin);
        tu.setJeniskelamin(s);

        try {
            TUkontrol tuk;
            tuk = TUkontrol.getKoneksi();
            tuk.update(tu);

            JOptionPane.showMessageDialog(this, "Data Siswa Berhasi Di Update");
            Nistextfield.setText("");
            NamaTextField.setText("");
            AlamatTextField.setText("");

        } catch (SQLException ex) {
            Logger.getLogger(SaveDataSiswa.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Data Siswa Tidak Berhasil Di Update");

        }
        TUFormDataSiswa tk = new TUFormDataSiswa();
        tk.refresh();
    }//GEN-LAST:event_UpdatebuttonActionPerformed

    private void KeluarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_KeluarActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_KeluarActionPerformed

    private void NistextfieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NistextfieldActionPerformed
        // TODO add your handling code here:
        String nis = Nistextfield.getText();
        try {
            TU tuk;
            tuk = TUkontrol.getKoneksi().CariDataSiswa(nis);

            NamaTextField.setText(tuk.getNama().getNama());
            Kelastextfield.setText(tuk.getKelas().getKelas());
            AlamatTextField.setText(tuk.getAlamat().getAlamat());
            JenisKelaminCombo.setSelectedItem(tuk.getJeniskelamin().getJeniskelamin());
            Nistextfield.setEnabled(true);
        } catch (SQLException ex) {
            Logger.getLogger(SaveDataSiswa.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_NistextfieldActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                EditDataSiswa dialog = new EditDataSiswa(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField AlamatTextField;
    private javax.swing.JButton Batalbutton;
    private javax.swing.JComboBox JenisKelaminCombo;
    private javax.swing.JTextField Kelastextfield;
    private javax.swing.JButton Keluar;
    private javax.swing.JTextField NamaTextField;
    private javax.swing.JTextField Nistextfield;
    private javax.swing.JButton Updatebutton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
